package com.zyx.javademo.clazz;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

/**
 * <p>获取成员标量的泛型
 *
 * @author Yaxi.Zhang
 * @since 2022/11/7 14:38
 */
public class User {
    private List<String> list;

    public static void main(String[] args) {
        try {
            Field field = User.class.getDeclaredField("list");
            Type genericType = field.getGenericType();
            if (genericType instanceof ParameterizedType) {
                Type actualType = ((ParameterizedType) genericType).getActualTypeArguments()[0];
                System.out.println(actualType.getTypeName());
            }
        } catch (Exception e) {
        }
    }
}
